# -*- coding: utf-8 -*-
# 首先，加载一个BGE向量模型：
from FlagEmbedding import FlagModel
 
model = FlagModel('bge-m3:latest',
                  query_instruction_for_retrieval="Represent this sentence for searching relevant passages:",use_fp16=True)
 
# 将语句作为模型输入，得到向量：
sentences_1 = ["I love NLP", "I love machine learning"]
sentences_2 = ["I love BGE", "I love text retrieval"]
embeddings_1 = model.encode(sentences_1)
embeddings_2 = model.encode(sentences_2)
 
# 取得向量后，通过内积计算相似度：
similarity = embeddings_1 @ embeddings_2.T
print(similarity)